package com.example.springbootdemo.text.en;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

public class IkWordUtil {
    public static Set<String> split(String text) {
        IKSegmenter ikSegmenter = new IKSegmenter(new StringReader(text), true);
        Set<String> set = new HashSet<>();
        // 分词
        try {
            Lexeme lexeme;
            while ((lexeme = ikSegmenter.next()) != null) {
                set.add(lexeme.getLexemeText());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return set;
    }
}
